/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistencia;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
 *
 * @author nao
 */
public class Conecta {
    
    	private static Conecta connection;
	public Connection conn;
	private String databaseName;
	private String host;
	private String username;
	private String passwd;
    
    	private Conecta () {
		this.databaseName = "banco_sistema"; 
		this.host = "localhost";
		this.username = "aluno";
		this.passwd = "aluno";
		try {
                                                      Class.forName("com.mysql.jdbc.Driver");
                                                      this.conn = DriverManager.getConnection("jdbc:mysql://"+this.host+"/"+this.databaseName+"?user="+this.username+"&password="+this.passwd);
		} catch (ClassNotFoundException e) {
                    System.out.println("ERRO");
			System.exit(1);
		} catch (SQLException e) {
                        System.out.println("ERRO1");
			System.exit(1);
		}		
	}
    
    	/**
	 * Singleton. Usado para que haja apenas uma conexão com o banco sendo usada no sistema
	 * @return uma instância desta classe
	 */
	public static synchronized Conecta getConnection(){
		if(connection == null) {
			connection = new Conecta();
	    }
	    return connection;
	 }
}
